﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _3D
{
    class TreeManager
    {
        List<Tree> forest;
        public TreeManager(Camera camera, GraphicsDevice graphics, float size, Texture2D texture, int lines, int numberpLine, Vector3 position)
        {
            forest = new List<Tree>();
            for (int i = 0; i < lines; i++)
            {
                for (int j = 0; j < numberpLine; j++)
                {
                    forest.Add(new Tree(camera, graphics, new Vector3(position.X + 2 * i * size, position.Y, position.Z + 4 * j * size), size, texture));
                }
            }
        }
        public void Update(Camera camera)
        {
            foreach (Tree t in forest)
                t.Update(camera);

            for (int i = 0; i < forest.Count; i++)
            {
                for (int j = 0; j < forest.Count; j++)
                {
                        if (i != j && (forest[j].distanceCamera.Length() < (int)forest[i].distanceCamera.Length()))
                        {
                            Tree temp = forest[i];
                            forest[i] = forest[j];
                            forest[j] = temp;
                        }
                }
            }   
        }
        public void Draw(GraphicsDevice graphics)
        {
            foreach (Tree t in forest)
                t.Draw(graphics);
        }
    }
}
